package com.example.testdemo.resources;

import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.atlas.bitmap.BuildableBitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.source.IBitmapTextureAtlasSource;
import org.andengine.opengl.texture.atlas.buildable.builder.BlackPawnTextureAtlasBuilder;
import org.andengine.opengl.texture.atlas.buildable.builder.ITextureAtlasBuilder.TextureAtlasBuilderException;
import org.andengine.opengl.texture.region.ITextureRegion;

import android.util.Log;

import com.example.testdemo.TankGameActivity;

public class ItemResources extends BaseResources {
	private final String TAG = ItemResources.class.getSimpleName();

	public BuildableBitmapTextureAtlas mTextureAtlas;

	public ITextureRegion mRegionDefence = null;
	public ITextureRegion mRegionGhost = null;
	public ITextureRegion mRegionLife = null;
	public ITextureRegion mRegionSpeed = null;

	public ItemResources(TankGameActivity activity) {
		super(activity);
	}
	
	@Override
	public void load(int resources) {
	    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("items/");
        mTextureAtlas = new BuildableBitmapTextureAtlas(
                mActivity.getTextureManager(), 512, 512, TextureOptions.BILINEAR);

        mRegionDefence = BitmapTextureAtlasTextureRegionFactory
                .createFromAsset(mTextureAtlas, mActivity, "defence.png");
        mRegionGhost = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
                mTextureAtlas, mActivity, "ghost.png");
        mRegionLife = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
                mTextureAtlas, mActivity, "life.png");
        mRegionSpeed = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
                mTextureAtlas, mActivity, "speed.png");

        try {
            mTextureAtlas
                    .build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(
                            10, 10, 10));
            mTextureAtlas.load();
        } catch (TextureAtlasBuilderException e) {
            Log.e(TAG, "Create DemoResources failed !", e);
        }
	}

	@Override
	public void unload(int resources) {
		mTextureAtlas.unload();
	}

}
